package controller

import (
	"demo/src/ioc"
	"net/http"
)

type Handler struct {
	Path   string
	Method string
	Handle
}

type Handle func(ctx map[string]any, r *http.Request, w http.ResponseWriter)

type Controller interface {
	ioc.Bean
	ToHandlers() []Handler
}

func PutHandler(path string, h Handle) Handler {
	return Handler{
		Path:   path,
		Method: http.MethodPut,
		Handle: h,
	}
}

func PatchHandler(path string, h Handle) Handler {
	return Handler{
		Path:   path,
		Method: http.MethodPatch,
		Handle: h,
	}
}

func OptionsHandler(path string, h Handle) Handler {
	return Handler{
		Path:   path,
		Method: http.MethodOptions,
		Handle: h,
	}
}
func PostHandler(path string, h Handle) Handler {
	return Handler{
		Path:   path,
		Method: http.MethodPost,
		Handle: h,
	}
}
func GetHandler(path string, h Handle) Handler {
	return Handler{
		Path:   path,
		Method: http.MethodGet,
		Handle: h,
	}
}
